package com.ymttest.business.service.productdata.impl;

import java.util.Arrays;
import java.util.List;

import com.ymt.core.tool.Logger;
import com.ymttest.business.service.ActivityCallService;
import com.ymttest.business.service.productdata.bean.ApplyProductBean;
import com.ymttest.business.service.productdata.bean.ProductActivitysBean;

public class NewActivityService extends AbstractActivityService{
	
	private ApplyProductBean applyProductBean;
	
	public NewActivityService(ApplyProductBean applyProductBean){
		this.applyProductBean = applyProductBean;
	}
	
	@Override
	protected ProductActivitysBean doAddProductInActivitys(String productId) {
		ProductActivitysBean productActivitysBean = new ProductActivitysBean();
		
		
		try{
			if (applyProductBean.getPreActivityCount()>0){
				List<Integer> activityIds = ActivityCallService.createActivityInFuture(applyProductBean.getPreActivityCount(), null);
				List<Integer> inaids = this.applyAndApproveProudctInActivitys(applyProductBean.getSellerId(),productId, activityIds);
				this.closeProductInActivitys(inaids);
				productActivitysBean.setPreActivitys(activityIds);
			}
			
			
			if (applyProductBean.isHasNowActivity()){
				int aid = ActivityCallService.createNoIsolationActivityInProcess();
				this.applyAndApproveProudctInActivitys(applyProductBean.getSellerId(),productId, Arrays.asList(aid));
				productActivitysBean.setNowActivity(aid);
			}

			
			if (applyProductBean.isHasNowAnotherActivity()){
				int aid = ActivityCallService.createIsolationActivityInProcess();
				this.applyAndApproveProudctInActivitys(applyProductBean.getSellerId(),productId, Arrays.asList(aid));
				productActivitysBean.setNowAnotherActivity(aid);
			}
			
			
			if (applyProductBean.getFutureActivityCount()>0){
				List<Integer> activityIds = ActivityCallService.createActivityInFuture(applyProductBean.getFutureActivityCount(), null);
				this.applyAndApproveProudctInActivitys(applyProductBean.getSellerId(),productId, activityIds);
				productActivitysBean.setFutureActivitys(activityIds);
			}
			
		}catch(Exception e){
			Logger.fail(e);
		}
		
		
		
		
		return productActivitysBean;
	}

}
